Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
strip-ansi
Advanced tools
The strip-ansi npm package is used to remove ANSI escape codes from strings. These codes are often used to provide coloring and formatting in terminal output, but they can be problematic when the text needs to be processed without these codes, such as logging to a file or displaying in a GUI.
Strip ANSI escape codes from a string
This feature allows you to remove any ANSI escape codes from a given string, leaving only the plain text without any formatting or color.
const stripAnsi = require('strip-ansi');
const coloredString = '\u001B[4mUnicorn\u001B[0m';
const strippedString = stripAnsi(coloredString);
console.log(strippedString); // 'Unicorn'
Chalk is a popular npm package that allows you to style terminal text with colors and other effects. While it is primarily used to add ANSI codes to strings, it also provides methods to strip color from strings, which can be used as an alternative to strip-ansi for this specific purpose.
ansi-regex is a package that provides a regular expression to match ANSI escape codes. It can be used in combination with string replace functions to remove ANSI codes from strings, similar to what strip-ansi does, but requires a bit more manual work.
ansi-colors is another library for styling terminal strings with ANSI colors. It also includes functionality to strip ANSI codes from strings. It is a lightweight alternative to chalk and can be used in place of strip-ansi for removing ANSI codes.
Strip ANSI escape codes
$ npm install --save strip-ansi
var stripAnsi = require('strip-ansi');
stripAnsi('\x1b[4mcake\x1b[0m');
//=> 'cake'
$ npm install --global strip-ansi
$ strip-ansi --help
Usage
$ strip-ansi <input-file> > <output-file>
$ cat <input-file> | strip-ansi > <output-file>
Example
$ strip-ansi unicorn.txt > unicorn-stripped.txt
MIT © Sindre Sorhus
FAQs
Strip ANSI escape codes from a string
The npm package strip-ansi receives a total of 118,545,177 weekly downloads. As such, strip-ansi popularity was classified as popular.
We found that strip-ansi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.